layui.use(['layer', 'form'], function () {
  var $ = layui.$
    , layer = layui.layer
    , form = layui.form
    , urls = "/erpmes";
  // from
  form.on('submit(jsonFormSubmit)', function (data) {
    layer.msg(JSON.stringify(data.field));
    var data1 = form.val("orderoperation");
    var load_index = layer.load(1, { time: 30 * 1000 });
    var formid = data1.otype
    var orders = data1.orders
    var orderArr = orders.split(/[\s,，\u3000]+/)  // /[^a-zA-Z0-9_.-]+/
    for (i in orderArr) {
      if(orderArr[i] == ""){ continue; }
      var order = { accid: "32424234", formid: formid, op: "sync", order: orderArr[i] }
      console.log(order);
      $.post({
        url: urls, // + "?csrfToken=" + data1.csrfToken,
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(order),
        dataType: 'text',
        async: false,
        headers: { "Csrf-Token": $('[name="csrfToken"]').val() },
        success: function (data) {
          console.log(data);
          // layer.msg("数据: \n" + data + "\n状态: " + status);
          var response = data.split("=>").last;
          insRow({
            formid: order.formid,
            order: order.order,
            op: order.op,
            result: data
          });
          //                    return false;
        }
      });
    }
    layer.close(load_index);
    return false;
  });
  function insRow(data) {
    var x = document.getElementById('resp-table').insertRow(0);
    var formid = x.insertCell(0);
    var order = x.insertCell(1);
    var op = x.insertCell(2);
    var result = x.insertCell(3);
    var formid_name = ""
    for (i in otypeList) {
      if (otypeList[i][0] == data.formid) formid_name = otypeList[i][1]
    }
    formid.innerHTML = formid_name;
    order.innerHTML = data.order;
    op.innerHTML = data.op;
    result.innerHTML = data.result;
  }

});